/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Database.OraConnection;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

/**
 *
 * @author Prasetyawan
 */
public class Barang {
    private int kode;
    private String nama;
    private String jenis;
    private int jumlah;
    private Connection con;

    public Barang (Connection koneksi){
        this.con = koneksi;
    }
public static Barang getBarang() throws SQLException {
        Barang kon = new Barang(OraConnection.getKoneksi());
        return kon;
    }

    public Barang() {
        
    }

    
//    public Barang() {
//        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//    }
    /**
     * @return the kode
     */
    public int getKode() {
        return kode;
    }

    /**
     * @param kode the kode to set
     */
    public void setKode(int kode) {
        this.kode = kode;
    }

    /**
     * @return the nama
     */
    public String getNama() {
        return nama;
    }

    /**
     * @param nama the nama to set
     */
    public void setNama(String nama) {
        this.nama = nama;
    }

    /**
     * @return the jenis
     */
    public String getJenis() {
        return jenis;
    }

    /**
     * @param jenis the jenis to set
     */
    public void setJenis(String jenis) {
        this.jenis = jenis;
    }

    /**
     * @return the jumlah
     */
    public int getJumlah() {
        return jumlah;
    }

    /**
     * @param jumlah the jumlah to set
     */
    public void setJumlah(int jumlah) {
        this.jumlah = jumlah;
    }
    
public void tambahBarang (Barang barang) throws SQLException {
    int kode = barang.getKode();
    String nama = barang.getNama();
    String jenis = barang.getJenis();
    int jumlah = barang.getJumlah();
    String sql = "insert into BARANG (KODEBARANG,NAMABARANG,JENIS,JUMLAH)"
                + " values ('" + kode + "','" + nama + "','" + jenis + "','" + jumlah + "')";
        Statement stat = con.createStatement();
        stat.executeUpdate(sql);
        con.close();
}    

public void lihatBarang (Barang barang) throws SQLException{
    String sql = "Select namabarang,jumlah from barang;";
    Statement stat = con.createStatement();
    stat.executeUpdate(sql);
    con.close();
}


}
